ensurecapacity method in java